$(function(){
	circleInfo.init();
});

var circleInfo = {
    cons : {
		num_top_nebula 		: 	4,
		num_top_post 		: 	3,
		num_max_tag 		: 	16,
		num_max_recent_posts:   6,
		num_max_recent_galaxies:   6
	},

    init:function(){
        render_top_bar();
        getCircles();
        
    },

    render:function(template,params){
        var arr = [];
        switch(template){
            case 'user-item':
                if(params['avatar']==0){
                    params['avatar']='img/noavatar_small.gif';
                }
                arr=[
                    '<li class="people-element" uid="',params['uid_to'],'"><div class="circle-avatar">',
                    '<a href="./circlefile.php?uid=',params['uid_to'],'"><img style="display:none"src="',params['avatar'],'" /></a>',
                    '</div><div class="name"><a href="./circlefile.php?uid=',params['uid_to'],'">',params['username'],'</a></div></li>'
                ];
                break;
            case 'user-list':
                arr=[
                    '<div class="circle-nebula">',params['name'],'</div><li id="list_',params['nid'],'" class="circle-people-list"><ul></ul></li>'
                ];
                break;
        }
        return arr.join('');
    }
}

function getCircles(){
    $.ziGET('getCircles',{'uid':session_user_info['uid']},function(r){
        var currentNid = [];
        var listContent = $('.circle-block ul');
        listContent.html("");
        if(r.length>0){      
            for(var i=0;i<r.length;i++){
                if( currentNid.indexOf(r[i]['nid'])==-1){
                    var userList = circleInfo.render('user-list', r[i]);
                    listContent.append(userList);
                    currentNid += r[i]['nid'];
                }
                var circleItem = circleInfo.render('user-item',r[i]);
                $('#list_'+r[i]['nid']).append(circleItem);
                var avatarImg = $('.circle-avatar img');
                if(avatarImg.length>0)
                    reSizeAvatar(avatarImg);
            }

        }
        else
            listContent.html("You don't have any friends");
    });
}
